<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Services extends CI_Controller {

    /**
     * Index Page for this controller.
     *
     * Maps to the following URL
     *         http://example.com/index.php/welcome
     *    - or -  
     *         http://example.com/index.php/welcome/index
     *    - or -
     * Since this controller is set as the default controller in 
     * config/routes.php, it's displayed at http://example.com/
     *
     * So any other public methods not prefixed with an underscore will
     * map to /index.php/welcome/<method_name>
     * @see http://codeigniter.com/user_guide/general/urls.html
     */
    public function index()
    {
         // Get info of Welcome
        $welcome = new Generalmodel();
        $conditions = array(
            "id" => 3
        );
        
        $welcome->tables = "laci_content";
        $welcome->conditions = $conditions;
        $welcome->getrecordinformation();
        $hasdata = $welcome->numrows;
        $welcomeinfo = $welcome->result;
        
        $data["contentdata"] = "";
        if($hasdata){
            $data["contentdata"] = $welcomeinfo[0]["content"];
        }
        
        //Get testimonial
        $testi = new Generalmodel();
        $testi->tables = "laci_testimonial";
        $testi->getrecordinformation();
        $hasdata = $testi->numrows;
        $testiinfo = $testi->result;
        
        $this->load->helper('text');

        $data["testimonial"] = "";
        if($hasdata){
            $data["testimonial"] = $testiinfo;
        }
        
        $data["title"] = "Ledesma Audiological Center Inc. | Services"; 
        $this->load->view('header', $data);
        $this->load->view('left');
        $this->load->view('services/services');
        $this->load->view('footer');
    }
    
       /**
    * @name: edit()
    * @uses: view edit page
    * 
    */
    function edit()
    {
        if($this->session->userdata("group") == ADMIN){
            // Get the content of Welcome
            $welcome = new Generalmodel();
            $conditions = array(
                "id" => 3
            );     
            
            $welcome->tables = "laci_content";
            $welcome->conditions = $conditions;
            $welcome->getrecordinformation();
            $welcomeinfo = $welcome->result;
            $hasdata = $welcome->numrows;
            
            $data["contentdata"] = "";
            if($hasdata){
                $data["contentdata"] = $welcomeinfo[0]["content"];
            }
            
            $data["title"] = "Ledesma Audiological Center Inc. | Services";
            $this->load->view('cpanel/admin_header', $data);
            $this->load->view('cpanel/admin_left', $data);
            $this->load->view('services/edit');
            $this->load->view('cpanel/admin_footer');
        } else {
            redirect(base_url() . "index.php/cpanel/login");
        }
    }
    
      /**
    * DATABASE METHODS
    */
    
    /**
    * @name : save()
    * @uses : 
    */
    function save()
    {
        if($this->session->userdata("group")){
            
            $save = new Generalmodel();
          $conditions = array(
            "id" => $this->uri->segment(3)
          );
          $tabledata = array(
            "content" => $_POST["txtareadata"]
          );
          
          $save->tables = "laci_content";
          $save->tabledata = $tabledata;
          $save->conditions = $conditions;
          $save->update();
          $isupdate = $save->result;
            
            if($isupdate){
                 $data["title"] = "Ledesma Audiological Center Inc. | Services";
                 $data["response"] = "Your Changes have been saved.";
                 
                $this->load->view('cpanel/admin_header', $data);   
                $this->load->view('cpanel/admin_left');   
                $this->load->view('message');
                $this->load->view('cpanel/admin_footer'); 
            } else {
                $data["title"] = "Ledesma Audiological Center Inc. | Services";
                 $data["response"] = "Error in Saving.";
                 
                $this->load->view('cpanel/admin_header', $data);
                $this->load->view('cpanel/admin_left');
                $this->load->view('message');
                $this->load->view('cpanel/admin_footer');
            }
        } else {
            redirect('cpanel/login');
        }            
    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */